package com.wmyg.antifake.fabric;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-05-12
 */
@Slf4j
@Service
public class AsyncService {

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    RabbitDao rabbitDao;

    @Async("asyncMoveDataToRedis")
    public void asyncUpdateRedis(MqAdaptPo po, String key) {
        String value = rabbitDao.sendFabricMessage(po);
        log.info("The async rabbit rpc result is {}", value);
        if (!StringUtils.isBlank(value)) {
            redisTemplate.opsForValue().set(key, value);
        }
    }

}
